﻿using FreeSql;
using FreeSql.DataAnnotations;
using Common;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;

namespace DBContext
{
    public class DbConfig
    {
        public static readonly IFreeSql DbContext;

        static DbConfig()
        {
            //string dbFileName = AppDomain.CurrentDomain.BaseDirectory + "config.db";
            //if (!File.Exists(dbFileName))
            //{
            //    Logger.Log.Info("create config db file");
            //    File.Create(dbFileName);
            //}
          
            DbContext = new FreeSqlBuilder()
                            .UseConnectionString(DataType.MySql, SysCfg.DBStr)
                            .UseAutoSyncStructure(true)
                            .Build();

            DbContext.Aop.CommandBefore += Aop_CommandBefore;
        }

        private static void Aop_CommandBefore(object sender, FreeSql.Aop.CommandBeforeEventArgs e)
        {
            Console.WriteLine(e.Command.CommandText);
        }

    }
}